package cn.edu.scau.cmi.linhuanrui.client;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

import cn.edu.scau.cmi.linhuanrui.singleton.Chairman;

public class SingletonClient extends Application {
	private Chairman chairman = null;

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) {
		primaryStage.setTitle("Singleton");
		primaryStage.setResizable(false); 
		Label label1 = new Label("单例模式 ");
		Label label2 = new Label("	请输入主席名称：");
		TextField field = new TextField();
		Button button = new Button("创建");
		TextArea area = new TextArea();
		FlowPane flowpane = new FlowPane();
		flowpane.setPadding(new Insets(10, 20, 30, 40));
		flowpane.setHgap(10);//设置控件之间的垂直间隔距离
		flowpane.setVgap(10);//设置控件之间的水平间隔距离
		flowpane.getChildren().addAll(label1,label2,field,button,area);
	    primaryStage.setScene(new Scene(flowpane, 600, 300));
	    primaryStage.show();
		button.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				chairman=Chairman.getInstance(field.getText());
				String warning="\n当前模式下已有对象被创建，不能再创建对象了！现在所获得的对象是：\n";
				if(area.getText().length()!=0)
					area.appendText(warning+chairman.getName()+chairman+"\n");
				else 
					area.setText(chairman.getName()+chairman+"\n");
			}
		});	
	}
}